import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5 import QtCore, QtGui, QtWidgets

import UI
from functools import partial

def exchange_rate(ui):
    print('exchange rate.')
    # 获取文本框数据
    input = ui.textEdit.toPlainText()
    try:
        result = float(input) * 6.7
    except Exception as e: 
        msg_warning('illegal input.')
    else:
        # 设置文本框数据
        ui.textEdit_2.setText(str(result))
        # ui.textEdit_2.setText('str(result)')
        ui.textBrowser.setText('ok')
        _translate = QtCore.QCoreApplication.translate
        ui.textBrowser.setHtml(_translate("MainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
    "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
    "p, li { white-space: pre-wrap; }\n"
    "</style></head><body style=\" font-family:\'SimSun\'; font-size:9pt; font-weight:400; font-style:normal;\">\n"
    "<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:28pt; font-weight:600;\">"+str(result)+"</span></p></body></html>"))

def msg_warning(msg):
    '''
    弹出警告框
    https://blog.csdn.net/qq_44880255/article/details/106967619
    '''
    reply = QtWidgets.QMessageBox.information(None, 
    "信息提示框", msg,QtWidgets.QMessageBox.Yes)
    # reply = QtWidgets.QMessageBox.information(None,"消息对话框","消息对话框正文",QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,QtWidgets.QMessageBox.Yes)
    print(reply)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    MainWindow = QMainWindow()
    ui = UI.Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    # 向槽（函数）传入参数
    er = partial(exchange_rate, ui)
    ui.PushButton.clicked.connect(er)
    sys.exit(app.exec_())
